﻿using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Excel.Expressions.Tests
{
    /// <summary>
    /// Summary description for GrammarTest1
    /// </summary>
    [TestClass]
    public class GrammarTest1
    {
        public GrammarTest1()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

#if AMIBIGOUS
        [TestMethod]
        public void TestMethod1()
        {
            Terminal<char> x = 'x';
            Nonterminal<char> E = "E";
            Nonterminal<char> S = "S";

            E.Definition = new Rules<char>()
            {
                () => S[false] + Terminal<char>.Default
            };

            S.Definition = new Rules<char>()
            {
                () => x + S + x,
                () => x
            };

            E.Initialize();
            E.Validate();

            Parser<char> input = "xx";

            bool actual = E.Parse(input);
            bool expected = false;

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void TestMethod2()
        {
            Terminal<char> x = 'x';
            Nonterminal<char> E = "E";
            Nonterminal<char> S = "S";

            E.Definition = new Rules<char>()
            {
                () => S[false] + Terminal<char>.Default
            };

            S.Definition = new Rules<char>()
            {
                () => x + S + x,
                () => x
            };

            E.Initialize();
            E.Validate();

            Parser<char> input = "xxx";

            bool actual = E.Parse(input);
            bool expected = true;

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void TestMethod3()
        {
            Terminal<char> x = 'x';
            Nonterminal<char> E = "E";
            Nonterminal<char> S = "S";

            E.Definition = new Rules<char>()
            {
                () => S[false] + Terminal<char>.Default
            };

            S.Definition = new Rules<char>()
            {
                () => x + S + x,
                () => x
            };

            E.Initialize();
            E.Validate();

            Parser<char> input = "x";

            bool actual = E.Parse(input);
            bool expected = true;

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void TestMethod4()
        {
            Terminal<char> x = 'x';
            Nonterminal<char> E = "E";
            Nonterminal<char> S = "S";

            E.Definition = new Rules<char>()
            {
                () => S[false] + Terminal<char>.Default
            };

            S.Definition = new Rules<char>()
            {
                () => x[false] + S + x[false],
                () => x[false]
            };

            E.Initialize();
            E.Validate();

            Parser<char> input = "xx";

            bool actual = E.Parse(input);
            bool expected = false;

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void TestMethod5()
        {
            Terminal<char> x = 'x';
            Nonterminal<char> E = "E";
            Nonterminal<char> S = "S";

            E.Definition = new Rules<char>()
            {
                () => S[false] + Terminal<char>.Default
            };

            S.Definition = new Rules<char>()
            {
                () => x[false] + S + x[false],
                () => x[false]
            };

            E.Initialize();
            E.Validate();

            Parser<char> input = "xxx";

            bool actual = E.Parse(input);
            bool expected = true;

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void TestMethod6()
        {
            Terminal<char> x = 'x';
            Nonterminal<char> E = "E";
            Nonterminal<char> S = "S";

            E.Definition = new Rules<char>()
            {
                () => S[false] + Terminal<char>.Default
            };

            S.Definition = new Rules<char>()
            {
                () => x[false] + S + x[false],
                () => x[false]
            };

            E.Initialize();
            E.Validate();

            Parser<char> input = "x";

            bool actual = E.Parse(input);
            bool expected = true;

            Assert.AreEqual(expected, actual);
        }
#endif
    }
}
